<template>

<!-- <el-backtop target=".page-component__scroll .el-scrollbar__wrap"> -->
  <div class="zuida demo-image__lazy" ref='zuida' v-cloak  >
    <div class="paihang" v-cloak>
      <rebang></rebang>
    </div>
    <div class="paihang1" ref="tips" style="display:none" @click="top"><i class="el-icon-upload2"></i>top</div>
    <div class="zuo"></div>
    <div class="you">
      <div v-for='(item,index) in list' :key="index" class="dan">
        <div class="tou">
        <el-image 
    style="width: 50px; height: 50px"
    :src="item.tou" 
    :preview-src-list="[item.tou]" lazy>
  </el-image>
          <!-- <img :src="wen.tou" alt=""> -->
          <div class="name">{{item.user}}<br>{{item.date}}</div>
        </div>

        <div class="title">{{item.title}} </div>
        <!-- <h4></h4> -->
      {{item.content}} <br/>
      <div class="img">
        <div v-for="(itemimg,index1) in item.img" :key="index1" class="imgzong">
        <!-- <img :src="itemimg" alt=""> -->
        <el-image 
    :src="itemimg" 
    :preview-src-list="item.img" class="getu" lazy>
  </el-image>
        </div>
      </div>
      <div class="pinglun">
        <div class="icon" @click="tiaoxiangxi(item.id)"><i class="el-icon-chat-line-square"></i>
        
        <!-- {{ping[item.id]}} -->
        <!-- {{pinglun(item.id)}} -->
        {{item.pinglun}}
        <!-- 11 -->
        </div>
        <!-- <div class="icon"><i class="el-icon-lollipop"></i>111</div> -->
        <div class="icon"><i class="el-icon-view"></i>{{item.liulan}}</div>
       
      </div>
    </div>
    <div class="meiyou" v-if="limit<sum">
      <!-- <h1>没有更多了</h1> -->
      ...正在加载中
    </div>
    <div class="meiyou" v-else>
      <!-- <h1>没有更多了</h1> -->
      没有更多了
    </div>
    </div>
    
    
  </div>
  <!-- </el-backtop> -->
  
</template>
<script>
// import Tou from './zujian/shang.vue'
import rebang from './zujian/rebang.vue'
export default {
  components:{
    // Tou
    rebang
  },
  data(){
    return {
      index:'2',
      list:[],
      litop:0,
      ping:[],
      limit:5,
      sum:0
    }
  },
  methods:{
    tiaoxiangxi(val){
      this.axios.get('/kan/'+val).then((res)=>{
      console.log(res);
    })
      this.$router.push('/wenzhang/'+val)
    },
    gundong(){
      let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
	        // console.log(scrollTop)
          this.litop=scrollTop
          // console.log(scrollTop);
        if(this.litop>=1000){
          this.$refs.tips.style.display='block'
        }
        else{
          this.$refs.tips.style.display='none'
        }
        var acc=window.innerHeight - (this.$refs.zuida.offsetTop - window.pageYOffset) - this.$refs.zuida.offsetHeight
        if(acc>7){
          if(this.limit<this.sum){
            this.limit+=5
            // console.log('hhh');
          this.qingqou()
          }
          
        }
    },
    top(){
      window.scrollTo(0,0)
    },
    shuaxin(){
      console.log('刷新了');
    },
    getbottom(){
      const distance=this.$refs.zuida
      console.log(distance);
    },
    qingqou(){
      this.axios.post('/wen',{id:this.limit}).then((res)=>{
        // console.log(res.data);
        for(var i=0;i<res.data.length;i++){
          res.data[i].img=eval(res.data[i].img)
          
          
        } 
        this.list=res.data
        
      })
    }
  },
  mounted(){
    this.ping=[]
    this.$store.commit('indexbian',this.index)
    window.addEventListener('scroll',this.gundong),
    // window.addEventListener('scroll',this.gundong),
    // this.open()
    window.addEventListener('beforeunload', this.shuaxin);
    // this.getbottom()
  },
  beforeDestroy () {
      		window.removeEventListener('scroll', this.gundong)
    	},
      created(){
      this.$store.commit('bianhui')
      this.qingqou()
      this.axios.get('/wen').then((res)=>{ 
        this.sum=res.data.length
        console.log(this.sum);
      })
      
    }
}
</script>
<style lang="less" scoped>
  .zuida{
    // overflow: scroll;
    // display: none;
    // overflow-y: scroll;
    width: 70%;
    margin: 0 auto;
    // height: 30000px;
    // background-color: red;
    margin-top: 40px;
    display: flex;
    justify-content:space-around;
    // background-color: red;
  }
  .zuo{
    width: 20%;
    // background-color: blue;
    // position:fixed;
    // top: 100px;
    // height: 100px;
  }
  .you{
    padding-top: 20px;
    width: 70%;
    background-color: #f1f1f1;
    // margin-left: 10px;
    padding-left: 20px;
    padding-right: 20px;
    border-radius: 20px;
  }
  .dan{
    width: 100%;
    .img{
      width: 100%;
      display: flex;
      // background-color: blueviolet;
      flex-wrap:wrap;
      // justify-content:space-around;
      // margin-right: ;
      .imgzong{
        margin-left: 4px;
        display: flex;
        justify-content:center;
        width: 32%;
        border-radius: 20px;
        // overflow: hidden;
        height: 260px;
        overflow: hidden;
        
      }
      
    }
    .tou{
      display: flex;
      color: #7b8084;
      margin-bottom: 10px;
      /deep/ .el-image{
        border-radius: 25px;
      }
    .name{
      margin-left: 20px;
      margin-top: 10px;
    }
  }
  .pinglun{
    margin-top: 10px;
  width: 100%;
  height: 34px;
  // background-color: rgb(95, 229, 77);
  display: flex;
  .icon{
    line-height: 34px;
    font-size: 18px;
    width: 30%;
    text-align: center;
  }
}
  }
  .paihang{
    width: 490px;
    // height: 580px;
    // background-color: #d4f1d5;
    border-radius: 10px;
    position: fixed;
    top: 130px;
    left: 24px;
  }
  .paihang1{
    width: 50px;
    height: 50px;
    background-color: #d4f1d5;
    border-radius: 10px;
    position: fixed;
    text-align: center;
    line-height: 50px;
    top: 300px;
    right:130px;
  }
  /deep/ .getu{
          width: 100%;
          // height: 100%;
          // 
          
          img{
            width: 100%;
            // height: 50%;
            // display: block;
            object-fit: cover;
          }
        }
.title{
    color: #000000;
    font-size: 22px;
  }
  [v-cloak]{
    display: none;
  }
  .meiyou{
    width: 100%;
    height: 30px;
    text-align: center;
    line-height: 30px;
  }
</style>